using System;
using NUnit.Framework;

namespace DatabaseUnitTesting.Utilities.Tests
{
    public class CustomAssert
    {
        public delegate void Statement();

        public static void AssertException(Statement statement, Type expected, string notThrownMessage,
                                           string unhandledExceptionMessage)
        {
            try
            {
                statement();
                Assert.Fail(notThrownMessage);
            } catch(AssertionException)
            {
                throw;
            } catch(Exception x)
            {
                if(x.GetType() != expected)
                    Assert.Fail(unhandledExceptionMessage + "\n\tExpected: " + expected + "\n\tReceived: " +
                                x.GetType() + "\n\tDetails: " + x);
            }
        }

        public static void AssertException(Statement statement, Type expected)
        {
            AssertException(statement, expected, String.Empty, String.Empty);
        }
    }
}